#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
	int binarySearch(vector<int>& nums, int target)
	{
		int left = 0;
		int right = nums.size() - 1;
		
		while(left <= right)
		{
			int mid = left + (right - left) / 2;
			
			if(nums[mid] == target)
			{
				return mid;
			}
			else if(nums[mid] < target)
			{
				left = mid + 1;
			}
			else
			{
				right = mid - 1;
			}
		}
		
		return -1;
	}
};

int main() 
{
	Solution sol;
	vector<int> nums = {-1, 0, 3, 5, 9, 12};
	int target;
	
	cout << "请输入目标值: ";
	cin >> target;
	
	int result = sol.binarySearch(nums, target);
	
	if (result != -1) 
	{
		cout << "目标值 " << target << " 出现在索引 " << result << endl;
	}
	else 
	{
		cout << "目标值 " << target << " 未找到，返回 -1" << endl;
	}
	
	return 0;
}

